package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.utils.CustomerException;
import com.briup.jz.bean.AccountApply;
import com.briup.jz.bean.AccountApplyExample;
import com.briup.jz.bean.extend.AccountApplyExtend;
import com.briup.jz.dao.AccountApplyMapper;
import com.briup.jz.dao.extend.AccountApplyExtendMapper;
import com.briup.jz.service.IAccountApplyService;

@Service
public class AccountApplyImpl implements IAccountApplyService{
	
	@Autowired
	private AccountApplyMapper AAM;
	@Autowired
	private AccountApplyExtendMapper acou;
	public List<AccountApply> findAll() {
		// TODO Auto-generated method stub
		return AAM.selectByExample(new AccountApplyExample());
	}

	@Override
	public   AccountApply findById(long id) throws CustomerException{
		// TODO Auto-generated method stub
		AccountApply AA = AAM.selectByPrimaryKey(id);
		if(AA==null) {
			throw new CustomerException("您所查询的Id不存在！");
		}
		
		return AA;
	}
	
	@Override
	public void saveOrUpdate(AccountApply AA) throws CustomerException {
		if(AA.getId()!=null) {
			AAM.insert(AA);
			} else {
			AAM.updateByPrimaryKey(AA);
		}
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		AccountApply AA = AAM.selectByPrimaryKey(id);
		if(AA == null) {
			throw new CustomerException("要删除的Id信息不存在");
		}
		AAM.deleteByPrimaryKey(id);
		
	}

	@Override
	public void changeStatus(Long id, String status,String reason) {
		// TODO Auto-generated method stub
		//获得信息
		AccountApply AA= findById(id);
		//设置状态
		AA.setStatus(status);
		AA.setReason(reason);
		//更新状态
		AAM.updateByPrimaryKey(AA);
	}

	@Override
	public List<AccountApplyExtend> pageQuery(int page, int pageSize, String status, String applyType,
			Long beginTime, Long endTime,Long user_id) {
		int pageIndex=(page-1)*pageSize;
		List<AccountApplyExtend> a=acou.pageQuery(pageIndex, pageSize, status, applyType, beginTime, endTime,user_id);
		return a;
	}
}
